package com.briup.day21;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class Test_Callable {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //2.实例化Callable对象
        Callable<String> ca = new MyCallable();
        //3.实例化任务调度对象
        FutureTask<String> ft = new FutureTask<String>(ca);
        //4.实例化Thread对象
        Thread th = new Thread(ft);
//        5.启动线程
        th.start();
        String s = ft.get();
        System.out.println(s);

    }
}
class MyCallable implements Callable<String> {
    @Override
    public String call() throws Exception {
        for (int i = 1; i <= 100; i++) {
            System.out.println("第"+i+"次跟女孩表白");
        }
        Thread.sleep(2000);
        return "答应";
    }
}
